﻿/* 关注对象
htmlID:显示关注与取消关注的Ａ标签的ＩＤ
updateCountID:显示关注数量的ＳＰＡＮ标签的ＩＤ
o:表示当前被触发的对象
调用：<a class="a4" href="javascript:attentionFun(215,5,'sadfasdfdsd',1,{htmlID:'AttentionHtml215',className:'a4',hoverClassName:'a3',title:'关注话题'})" id="AttentionHtml215">
                                        关注话题 </a>
*/
function attentionFun(objID, yiBaObj, title, flag, options) {
    //参数对象
    var options = $.extend({
        htmlID: '', //要更新的链接文本
        updateCountID: '', //要更新的统计文本
        className: '', //要更新的CSS名
        hoverClassName: '', //切换时的CSS名
        title: '关注',
        isText: false//是否为文字（+－号）
    }, options || {});
    $.ajax({
        type: 'POST',
        url: '/YiBa/AttentionTopic',
        data: { objID: objID, yiBaObj: yiBaObj, title: title, flag: flag },
        success: function (data) {
            if (options.htmlID == '' || options.htmlID == 'undefined') { //兼容前一版本
                var locationHref = location.href;
                var urlArr = location.href.split(window.location.host)[1].split("/");
                if (urlArr[1] == "Workshop_Job" && urlArr[2] == "Detail") {
                    locationHref = document.referrer;
                }
                else if (urlArr[1] == "YiBa" && urlArr[2] == "TalkDetail") {
                    locationHref = document.referrer;
                }
                boxy_HrefFun(data, locationHref);
            }
            else {
                Boxy_Extensions.alertDelayFun(data.msg, 2000);
                if (data.res) {//如果成功操作，然后更新ＤＩＶ文字

                    if (options.isText) {//是否显示文字+－符号
                        $('#' + options.htmlID).html("<i  class='guanzhu_i'>-</i>");
                    }
                    if (flag == "1") {
                        $('#' + options.htmlID).attr({
                            "href": "javascript:attentionFun(" + objID + "," + yiBaObj + ",'取消关注',0,{htmlID:'" + options.htmlID + "',updateCountID:'" + options.updateCountID + "',className:'" + options.hoverClassName + "',hoverClassName:'" + options.className + "',isText:" + options.isText + ",title:'" + options.title + "'})",
                            "id": options.htmlID,
                            "class": options.hoverClassName
                        });
                        if (options.isText) {
                            $('#' + options.htmlID).html("<i  class='guanzhu_i'>-</i>取消关注");
                        } else {
                            $('#' + options.htmlID).html("取消关注");
                        }
                        if (options.updateCountID != '' && options.updateCountID != 'undefined') {
                            $('#' + options.updateCountID).html(parseInt($('#' + options.updateCountID).html()) + 1)
                        }
                    }
                    else {
                        $('#' + options.htmlID).attr({
                            "href": "javascript:attentionFun(" + objID + "," + yiBaObj + ",'关注',1,{htmlID:'" + options.htmlID + "',updateCountID:'" + options.updateCountID + "',className:'" + options.hoverClassName + "',hoverClassName:'" + options.className + "',isText:" + options.isText + ",title:'" + options.title + "'})",
                            "id": options.htmlID,
                            "class": options.hoverClassName
                        });
                        if (options.isText) {
                            $('#' + options.htmlID).html("<i class='guanzhu_i'>+</i>" + options.title + "");
                        }
                        else {
                            $('#' + options.htmlID).html(options.title);
                        }
                        if (options.updateCountID != '' && options.updateCountID != 'undefined') {
                            $('#' + options.updateCountID).html(parseInt($('#' + options.updateCountID).html()) == 0 ? "0" : parseInt($('#' + options.updateCountID).html()) - 1);
                        }
                    }
                }
            }
        }
    });
}